<template>
  <view class="home-container">
    <view class="search-home">
      <my-search @click="gotoSearch"></my-search>
    </view>
    <!-- //轮播图区域 -->
    <view class="swiperBox">
      <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular='true'>
        <swiper-item v-for="(item,i) in swiperList" :key="i">
          <navigator class="swiper-item" :url="'/subpak/godds_detail/godds_detail?goods_id='+item.goods_id">
            <image :src="item.image_src"></image>
          </navigator>
        </swiper-item>
      </swiper>
      <!--分类区域  -->
      <view class="cate-box">
        <view class="cate-item" v-for="(item,i) in cateList" :key='i' @click="goToNextHeadle(item.name)">
          <image :src="item.image_src"></image>
        </view>
      </view>
      <!-- 楼层 -->
      <view class="floor-box">
        <!-- 标题渲染 -->
        <view class="floor-list" v-for="(item,i) in floorList" :key="i">
          <view class="floor-title">
            <image :src="item.floor_title.image_src" class="floor-list-img"></image>
          </view>
          <view class="floor-image-box">
            <!-- 商品渲染  左侧-->
            <view class="floor-ifo-left">
              <navigator :url="item.product_list[0].url">
                <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}"
                  mode="widthFix"></image>
              </navigator>
            </view>
            <!-- 商品渲染右侧 -->

            <view class="floor-ifo-rightImage">
              <view class="floor-ifo-right" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2!==0">
                <navigator :url="item2.url">
                  <image :src="item2.image_src" :style="{width:item2.image_width+'rpx'}" mode="widthFix"></image>
                </navigator>
              </view>
            </view>
          </view>
        </view>

      </view>
    </view>
  </view>



</template>

<script>
  import badgeMix from "../../mixins/tabbar-badge.js"
  export default {
    mixins:[badgeMix],
    data() {
      return {
        swiperList: [],
        cateList: [],
        floorList: []
      }
    },
    onLoad() {
      this.getSwiperList(),
        this.getCateList(),
        this.getFloorList()
    },
    methods: {
      async getSwiperList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        // console.log(res)
        if (res.meta.status !== 200) {
          return uni.showMsg()
        }


        // console.log(res.message)
        this.swiperList = res.message;
        // console.log(this.swiperList + "2222")
      },
      async getCateList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        // console.log(res,+'333')
        if (res.meta.status !== 200) {
          return uni.showMsg()
        }
        this.cateList = res.message
      },
      goToNextHeadle(item) {
        console.log(item)
        if (item === '分类') {
          uni.switchTab({
            url: "/pages/cate/cate"
          })
        }
      },

      async getFloorList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        // console.log(res)

        if (res.meta.status !== 200) {
          return uni.showMsg()
        }
        res.message.forEach((floor) => {
          // console.log(floor.product_list)
          floor.product_list.forEach(pro => {
            // console.log(pro.navigator_url)
            pro.url = '/subpak/goods_list/goods_list?' + pro.navigator_url.split("?")[1]
          })
        })
        this.floorList = res.message
      },
      gotoSearch(){
        uni.navigateTo({
          url:"../../subpak/search/search"
        })
      }
    },

  }
</script>

<style lang="scss">
  .search-home{
    position: sticky;
    top: 0;
    z-index: 999;
  }
  swiper {
    height: 330rpx;

    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }

  .cate-box {
    display: flex;
    justify-content: space-around;
    margin: 15rpx 0;

    .cate-item {
      width: 128rpx;
      height: 140rpx;

      image {
        width: 128rpx;
        height: 140rpx;
      }
    }
  }

  /*  .floor-list{
    display: flex;
  } */
  .floor-title {
    height: 60rpx;
    width: 100%;
    display: flex;
  }

  .floor-image-box {
    display: flex;
    padding-left: 10rpx;
  }

  .floor-list-img {
    height: 60rpx;
    width: 100%;
    display: flex;
  }

  .floor-ifo-rightImage {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
  }
</style>
